package com.esun.cheetah.view.setting.listener;

import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;

import com.esun.cheetah.view.setting.service.NotificationService;

/**
 * 手机状态改变监听
 * @author renfj
 *
 */
public class PhoneStateChangeListener extends PhoneStateListener {

	private final NotificationService notificationService;

	public PhoneStateChangeListener(NotificationService notificationService) {
		this.notificationService = notificationService;
	}

	@Override
	public void onDataConnectionStateChanged(int state) {
		super.onDataConnectionStateChanged(state);
		if (state == TelephonyManager.DATA_CONNECTED) {
			notificationService.connect();
		}
	}

	@SuppressWarnings("unused")
	private String getState(int state) {
		switch (state) {
		case 0: // '\0'
			return "DATA_DISCONNECTED";
		case 1: // '\001'
			return "DATA_CONNECTING";
		case 2: // '\002'
			return "DATA_CONNECTED";
		case 3: // '\003'
			return "DATA_SUSPENDED";
		}
		return "DATA_<UNKNOWN>";
	}

}
